class FriendManager:
    def __init__(self):
        self.friends = {}
        self.groups = {}

    def add_friend(self, name):
        if name in self.friends:
            print("好友已存在。")
        else:
            self.friends[name] = name
            print("好友添加成功。")

    def delete_friend(self, name):
        if name in self.friends:
            del self.friends[name]
            print("删除成功。")
        else:
            print("好友不存在。")

    def remark_friend(self, old_name, new_name):
        if old_name in self.friends:
            self.friends[new_name] = self.friends.pop(old_name)
            print("备注成功。")
        else:
            print("好友不存在。")

    def show_friends(self, group_name=None):
        if group_name:
            if group_name in self.groups and self.groups[group_name]:
                print("分组中的好友：")
                for friend in self.groups[group_name]:
                    print(friend)
            else:
                print("分组不存在或分组中没有好友。")
        else:
            print("所有好友：")
            for friend in self.friends:
                print(friend)

    def create_group(self, group_name):
        if group_name in self.groups:
            print("分组已存在。")
        else:
            self.groups[group_name] = []
            print("分组创建成功。")

    def add_friend_to_group(self, friend_name, group_name):
        if friend_name in self.friends and group_name in self.groups:
            self.groups[group_name].append(friend_name)
            print("好友分组成功。")
        else:
            print("好友不存在或分组不存在。")

    def delete_group(self, group_name):
        if group_name in self.groups:
            del self.groups[group_name]
            print("分组删除成功。")
        else:
            print("分组不存在。")

    def show_groups(self):
        for group_name, friends in self.groups.items():
            print(f"{group_name}: {friends}")

def main():
    manager = FriendManager()
    while True:
        print("\n好友管理系统")
        print("1. 添加好友")
        print("2. 删除好友")
        print("3. 备注好友")
        print("4. 展示好友")
        print("5. 好友分组")
        print("6. 退出")
        choice = input("请输入您的选项：")

        if choice == '1':
            name = input("请输入要添加的好友：")
            manager.add_friend(name)
        elif choice == '2':
            name = input("请输入删除好友姓名：")
            manager.delete_friend(name)
        elif choice == '3':
            old_name = input("请输入要修改的好友姓名：")
            new_name = input("请输入修改后的好友姓名：")
            manager.remark_friend(old_name, new_name)
        elif choice == '4':
            print("1. 展示所有好友")
            print("2. 展示分组中的好友")
            sub_choice = input("请输入您的选项：")
            if sub_choice == '1':
                manager.show_friends()
            elif sub_choice == '2':
                group_name = input("请输入分组名：")
                manager.show_friends(group_name)
        elif choice == '5':
            print("1. 创建分组")
            print("2. 添加好友到分组")
            print("3. 删除分组")
            print("4. 展示分组")
            sub_choice = input("请输入您的选项：")
            if sub_choice == '1':
                group_name = input("请输入分组名：")
                manager.create_group(group_name)
            elif sub_choice == '2':
                friend_name = input("请输入好友名：")
                group_name = input("请输入分组名：")
                manager.add_friend_to_group(friend_name, group_name)
            elif sub_choice == '3':
                group_name = input("请输入分组名：")
                manager.delete_group(group_name)
            elif sub_choice == '4':
                manager.show_groups()
        elif choice == '6':
            print("退出系统。")
            break
        else:
            print("无效选项，请重新输入。")

if __name__ == "__main__":
    main()